#include "HelloWorldScene.h"
#include "GameCenterScene.h"
#include "GameManager.h"
//#include "SimpleAudioEngine.h"  
//#include "audio/include/AudioEngine.h"  


USING_NS_CC;
using namespace ui;
using namespace cocostudio;

//using namespace experimental;
//using namespace CocosDenshion; 

Scene* HelloWorld::createScene()
{
    // 'scene' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    
	auto rootNode = CSLoader::createNode("MainScene.csb");
	addChild(rootNode);
	auto btn1 = dynamic_cast<Button*>(rootNode->getChildByName("btn_Start"));
	struct callBackFunctor {
		void operator() (Ref* sender) const {
			Director::getInstance()->replaceScene(TransitionCrossFade::create(.2f, GameCenter::createScene()));
			//SimpleAudioEngine::sharedEngine()->playEffect("sound/shake.mp3");
			//experimental::AudioEngine::play2d()
			//int audioID=experimental::AudioEngine::play2d("sound/shake.mp3");
		}
	};
	
	Widget::ccWidgetClickCallback callback = callBackFunctor();
	btn1->addClickEventListener(callback);

	GameManager* instance = GameManager::getInstance();
	ValueVector star_val = FileUtils::getInstance()->getValueVectorFromFile("itemInfo1.plist");
	instance->BriefsVector = star_val.at(0).asValueVector();
	instance->PropsVector = star_val.at(1).asValueVector();
	instance->DiamondVector = star_val.at(2).asValueVector();
	instance->GoldVector = star_val.at(3).asValueVector();

    return true;
}


void HelloWorld::menuCloseCallback(Ref* pSender)
{
    Director::getInstance()->end();

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    exit(0);
#endif
}


